package com.lsl.test1;

/**
 * @author lishuailong
 * @create 2020-06-15 17:05
 */
public class TestC {
    public static void main(String[] args) {

        Windowx windowx = new Windowx(100);

        Thread thread1 = new Thread(windowx);
        thread1.setName("窗口1");
        Thread thread2 = new Thread(windowx);
        thread2.setName("窗口2");
        Thread thread3 = new Thread(windowx);
        thread3.setName("窗口3");

        thread1.start();
        thread2.start();
        thread3.start();

    }
}


class Windowx implements Runnable {
    private int ps;

    public Windowx(int ps) {
        this.ps = ps;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (this){
                if (ps > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "卖出了" + ps + "号票！");
                    ps--;
                } else {
                    break;
                }
            }
        }
    }
}
